package sg.edu.ntu.bloch.tictactoe.engine;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

public class Util {
	
	private static final Logger _log = Logger.getLogger(Board.class);
	
	public static void printBoard(Board b) {
		String result = "";

		for (int x = 0; x < b.getSize(); x++) {
			for (int y = 0; y < b.getSize(); y++) {

				Seed curr = b.getSeed(x, y);

				if (curr == null) {
					result += "-\\";
				} else {
					result += Piece.getPieceString(curr.getPlayer()) + "\\";
				}
			}

			result += "\n";
		}
		
		_log.debug("\n"+result);
		
	}
	
}

class Piece {
	
	public final static Integer getPieceString(Player player) {

		if (Piece.playerList.containsKey(player)) {
			return Piece.playerList.get(player);
		} else {
			Piece.playerList.put(player, Piece.count++);
			return Piece.playerList.get(player);
		}

	}
	
	private static int count = 0;
	private static Map<Player, Integer> playerList = new HashMap<Player, Integer>();

	private Piece() {
	}
}
